package io.renren.modules.app.controller;

import com.alibaba.fastjson.JSONObject;
import io.renren.common.utils.R;
import io.renren.modules.app.annotation.Login;
import io.renren.modules.carcustomerinfo.dto.CarCustomerInfoDTO;
import io.renren.modules.carcustomerinfo.service.CarCustomerInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;

/**
 * 车辆预约
 */
@Api(tags = "车辆预约")
@RestController
@RequestMapping("/app")
public class AppSubscribeController {
    @Autowired
    private CarCustomerInfoService carCustomerInfoService;

    /**
     * 客户预约
     */
    @Login
    @ApiOperation("客户预约")
    @PostMapping("/subscribe")
    public R subscribe(@RequestBody CarCustomerInfoDTO dto, HttpServletRequest request){
        Long userId = (Long) request.getAttribute("userId");
        dto.setTbUserId(userId);
        carCustomerInfoService.subscribe(dto);
        return R.ok();
    }

    /**
     * 客户预约列表
     */
    @Login
    @ApiOperation("客户预约列表")
    @GetMapping("/subscribelist")
    public R subscribelist(@RequestParam Map<String, Object> params, HttpServletRequest request){
        Long userId = (Long) request.getAttribute("userId");
        JSONObject jsonObject = carCustomerInfoService.subscribelist(userId);
        return R.ok().put("jsonObject",jsonObject);
    }
}
